home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / 93src.lha / src / modules / representation.sml < prev    next >
Encoding:
Text File  |  1993-01-27  |  10.1 KB  |  260 lines

  1. (***************************************************************************
  2.  
  3.  REPRESENTATION.SML This files gives a description of the main types used
  4.  to represent structures. 
  5.  
  6.  - Most of the types are transfered directly from the module description.
  7.  - There is a new "fctSignature" with all the related types.
  8.  - Note FCT_FORMAL, FCT_ABSFB and FCT_INSTANCE in Functor.
  9.    Their meaning is close to   the meaning in Structure of STR_FORMAL,
  10.    STR_ABSFB and INSTANCE.(note: should be rewriten in STR_INSTANCE).
  11.  - APPLY describes an application of a functor to an argument. It is simplified
  12.    into the result alone if we the functor is not a parameter of an
  13.    enclosing functor.
  14.  - FULL_SIG is used when we don't want any coercion of a structure in an
  15.    instance
  16.  - IRRELEVANT means that there is no reason for giving a kind to the signature
  17.    because it has been elaborated with the structure it describes. The contents
  18.    of kind describes how to build the skeleton of a structure instance of the
  19.    signature.
  20.  
  21.  
  22. Constraints: 
  23.  
  24. - In INSTANCEs, arrays must contain objects in the order of their definition
  25.   (at least for origin structures). It is used to abstract them.
  26.  
  27. - In true signatures, the symbol field must contain the list of bound names
  28.   in the order of their definition.
  29.  
  30. - In a functor body, if the argument is necesary, it is stored at index 0.
  31.  
  32. - SIMPLEs are only used for toplevel structures. Arguments of functors (after
  33.   coercion by the functor signature) and functor bodies must be instances.
  34.  
  35.  ***************************************************************************)
  36.  
  37. structure Modules = struct
  38.  
  39. local
  40.   open Types Symbol Access
  41. in
  42.  
  43. (* symbolic paths *)
  44. type spath = symbol list
  45.  
  46. (* position in files *)
  47. type strpos = int;
  48.  
  49. (* BINDINGS *)
  50.  
  51. (* The following datatypes are used to describe objects stored in static
  52.    environments.
  53.    - Name is the symbol used to access them but it is not necessarily the key
  54.    stored in the environment.
  55.    - Binding is the value itself.
  56.    - Access describes the path to follow to get the value of the component in
  57.    the dynamic representation of the object. In a structure it is the slot
  58.    where the object is stored. In the global environment, it is a PATH with
  59.    the global lvar to look for *)
  60.  
  61.  
  62. datatype fixityVar
  63.     = FIXvar of {name: Symbol.symbol, binding: Fixity.fixity}
  64.  
  65. datatype signatureVar
  66.     = SIGvar of {name: Symbol.symbol, binding: Signature}
  67.  
  68. and funsigVar 
  69.     = FSIGvar of {name: Symbol.symbol, binding: FctSignature}
  70.  
  71. and structureVar
  72.     = STRvar of {name: Symbol.symbol,
  73.          access: Access.access,       
  74.          binding: Structure (* was strb *)}
  75.  
  76. and functorVar
  77.     = FCTvar of {name: Symbol.symbol,
  78.          access: Access.access,
  79.          binding: Functor}
  80.  
  81. (* all those types are grouped by binding *)
  82.  
  83. and binding
  84.     = VARbind of Variables.var
  85.     | CONbind of Types.datacon
  86.     | TYCbind of Types.tycon
  87.     | SIGbind of signatureVar
  88.     | STRbind of structureVar
  89.     | FSIGbind of funsigVar
  90.     | FCTbind of functorVar
  91.     | FIXbind of fixityVar
  92.  
  93. (* SIGNATURES *)
  94.  
  95. and Signature
  96.     = SIG of { (* the ordered list of symbols defined (in sig only) *)
  97.           symbols : Symbol.symbol list ref,
  98.               env : env ref, (* specification of objects *)
  99.               stamp : Stamps.stamp, (* for fast equality test *)
  100.               path : symbol option, (* used for printing only *)
  101.               kind : sigkind ref}
  102.     (* the signature is the full actual structure *)
  103.     | FULL_SIG 
  104.     (* bogus signature *)
  105.     | ERROR_SIG
  106.  
  107. (* a structure obtained by coercion by a signature is of type instance.
  108.    signatures contain enough information to build the skeleton of the
  109.    instance *)
  110.  
  111. and sigkind 
  112.   (* This is a toplevel signature. All sharing constraints have been pushed
  113.      to that level and are expressed by reference to the root of the signature
  114.      strcount, fctcount and typecount are the size of the arrays needed to
  115.      build an instance of the signature. Slotcount gives the size of the
  116.      record denoting it. *)
  117.   = TOP of {
  118.     (* specifies the shape of the skeleton of an instance *)
  119.     strcount : int,
  120.     fctcount : int, 
  121.     typecount : int,
  122.     slotcount : int,
  123.  
  124.     (* specifies the constraints of sharing *)
  125.     sConstraints : {internal: spath list,
  126.             external: Structure option} list,
  127.     tConstraints : {internal: spath list,
  128.             external: Types.tycon option} list}
  129.   (* The signature is embedded in a top signature. The instance structure will
  130.      share the instance arrays with its embedding structure *)
  131.   | EMBEDDED 
  132.   (* the kind field is irrelevant in a signature of an instance. It is true
  133.      when the signature is obtained while building the structure. But even
  134.      then it is important to maintain the invariant that signature contains
  135.      enough information to rebuild the structure because it is used by
  136.      instantiate. *)
  137.   | IRRELEVANT 
  138.  
  139. (* FUNCTOR SIGNATURE: note the parallel between this and fct and sig *)
  140. and FctSignature
  141.     (* a complete specification of a functor signature *)
  142.     = FSIG of {path : symbol option,     (* its name (toplevel object) *)
  143.            paramName : symbol,     (* name of the parameter (printing) *)
  144.                argument : Signature,    (* signature of the argument *)
  145.                body : Signature}    (* signature of the body *)
  146.     (* the signature is irrelevant: look at the actual functor to get it *)
  147.     | FULL_FSIG
  148.     (* the signature is bogus *)
  149.     | ERROR_FSIG
  150.  
  151. (* STRUCTURES *)
  152. and Structure
  153.     (* a simple raw structure defined at toplevel *)
  154.     = SIMPLE of {stamp: Stamps.stamp,    (* stamp *)
  155.                  env: env,        (* environment defining the bindings *)
  156.                  path:spath        (* path to the structure *)
  157.       }
  158.     (* result of coercing the origin structure by a signature. *)
  159.     | INSTANCE of
  160.          {sign : Signature,        (* signature describing the instance *)
  161.           subStrs : Structure array,    (* structure array *)
  162.           subFcts : Functor array,    (* functor array *)
  163.           types : Types.tycon array,    (* types array *)
  164.           origin : Structure,        (* structure coerced by sign *)
  165.           path : spath            (* path to the structure *)
  166.       }
  167.     (* representation of a binding coming from an opened structure *)
  168.     | STR_OPEN of {pos : int list, spec : Signature, name : spath}
  169.     (* representation of a formal binding in a signature *)
  170.     | STR_FORMAL of {pos : strpos, spec : Signature}
  171.     (* abstracted binding in a functor body *)
  172.     | STR_ABSFB of absfbpos
  173.     (* used to give a stamp to instance without origin *)
  174.     | SELF of Stamps.stamp
  175.     (* describe the result res of the application of functor fct to arg *)
  176.     | APPLY of {fct: Functor, arg: Structure, res: Structure} 
  177.     (* an error has been found *)
  178.     | ERROR_STR
  179.  
  180. (* FUNCTORS *)
  181.  
  182. (* Invariants maintained in functors:
  183.    - The parent structure must be an instance or ERROR_STR (which means that
  184.    the functor is a toplevel one).
  185.    - The body describes an INSTANCE structure. It is a recepee to build it.
  186.     - str describes the root of the result
  187.     - sequences describe basic operation. Objects resulting from these
  188.       are identified by the position of the basic operation is the sequence
  189.     - strseq describe how to build a one level structure from other 
  190.       structures types or functors obtained by
  191.         - looking up in the parameter ABSFB(PARAM path)
  192.         - looking up in the result of another basic operation
  193.         ABSFB(SEQ number) or ABSFB(SEQ(number,path))
  194.         - applying a functor to a structure (structure of the APPLY form)
  195.         - taking the object as is if it is not in any of the previous
  196.           categories
  197.    - The result structures verifies certain properties depending on how it
  198.      has been obtained.
  199.     - if the specification is just a variable (a component of the parameter
  200.       or of the outside world). Then the body is just that structure
  201.     - if the specification is a complete definition of a structure, then
  202.       this structure is an INSTANCE whose substructure stored in 0 is
  203.       the argument. The argument is a pair made of the Parent structure
  204.       and of the actual parameter. It is an instance. The way it is done
  205.       now leads that the parent is in slot 0 and the parameter in slot 1
  206.     - if it is an application of another functor to an argument, then the
  207.       argument verifies the constraints as defined previously but it is
  208.       the result of the second application that is given as body
  209. *)
  210.  
  211. and Functor
  212.     (* raw functor *)
  213.     = FCT of {stamp: Stamps.stamp,     (* stamp for identification and age *)
  214.           parent: Structure,    (* parent structure *)
  215.               paramName: symbol,    (* formal name of the parameter *)
  216.               argument: Signature,    (* signature coercing the argument *)
  217.               body: {strseq: Structure list,    (* sequence of orders to fol *)
  218.                      fctseq: Functor list,    (* low to build a new instan *)
  219.                      tyseq: tycon list,        (* ce of the body         *)
  220.                      str: Structure,            (* a list of actions        *) 
  221.                      fullstr: Structure}}       (* the full str, only used for
  222.                                                    representation analysis *)
  223.     (* as STR_FORMAL *)
  224.     | FCT_FORMAL of {pos: strpos, spec: FctSignature}
  225.     (* as STR_OPEN *)
  226.     | FCT_OPEN of {pos : int list, spec : FctSignature, name : spath}
  227.     (* as INSTANCE a new parent may be given and used in FctSignature *)
  228.     | FCT_INSTANCE of {fsig:FctSignature,fct:Functor,parent: Structure}
  229.     (* as STR_ABSFB *)
  230.     | FCT_ABSFB of absfbpos
  231.     (* as ERROR_STR *)
  232.     | ERROR_FCT
  233.  
  234. withtype env = binding Env.env
  235.  
  236.  
  237. (* THINNING *)
  238.  
  239. datatype trans 
  240.      (* old position, used for val, exn, or unthinned str *)
  241.    = VALtrans of access * ty * ty option
  242.      (* old str position, substr thinning *)
  243.    | THINtrans of access * lvar * trans list
  244.      (* functor body thinning, same as previous for the fields 
  245.         idea: THINtrans translates into fn str => {strthined}
  246.               FCTtrans translates into 
  247.         fn f => fn a => case (f a) of str => {strthined}
  248.     where strthined is describe by the trans list
  249.       *)
  250.    | FCTtrans of access * Signature * thinning * thinning
  251.      (* constructor as value component *)
  252.    | CONtrans of datacon * ty option
  253.  
  254. withtype thinning = (lvar * trans list) option
  255.  
  256. type fctThinning = (thinning * thinning) option
  257. end
  258.  
  259. end (* structure Moduless *)
  260.